﻿#ifndef TCP_SERVER_H
#define TCP_SERVER_H

#include <QTcpServer>
#include <QTcpSocket>
#include <QHostAddress>
#include <QMessageBox>

class TCP_Server:public QObject
{
    Q_OBJECT
public:
    TCP_Server();
    ~TCP_Server();

public slots:
    //开启监听
    void StartListen(const QString ipAddress, const quint16 port);
    void StopListen();
    //客户端管理
    void KickClient(QString ip);
    void SendMessage(const QString ip, const QByteArray msg);
    void HasClientConnect();
    void HasClientDisconnect();
    void ReciveClientMessage();
signals:
    //成功开启监听
    void ListenStarted();
    //将接收客户端的消息通知到主窗口
    void ClientsMsgToUI(QByteArray message);
    //将服务器消息通知到主窗口
    void TcpServerMsgToUI(QString message);
    //客户端列表更新
    void UpdateClientsToUI(QString method, QString IP);
private:
    QTcpServer *Server;
    QTcpSocket *ObjClient;
    //Hash(ip_str，socket)
    QHash<QString,QTcpSocket*> MyClients;
};

#endif // TCP_SERVER_H
